﻿Imports System.Drawing

Public Class ControlRow
  ' If _buttons is count=0, then this is a "add more buttons" Row
  Private _buttons As New List(Of ControlButton)
  Private _lastRectangle As Rectangle = Rectangle.Empty

  Public Sub New()
  End Sub

  Public Sub New(ByVal emptyButtonCount As Integer)
    For i As Integer = 0 To emptyButtonCount - 1
      Me._buttons.Add(New ControlButton(0, 0))
    Next
  End Sub

  Public ReadOnly Property Buttons() As List(Of ControlButton)
    Get
      Return Me._buttons
    End Get
  End Property

  Public ReadOnly Property LastRectangle() As Rectangle
    Get
      Return Me._lastRectangle
    End Get
  End Property

  Public Sub DrawRow(ByVal g As Graphics, ByVal rect As Rectangle, ByVal dpiFactor As Single, Optional ByVal drawRowOutline As Boolean = False, Optional ByVal drawButtonOutline As Boolean = False)
    If Me._buttons.Count > 0 Then
      Dim butWidth As Integer = rect.Width / Me._buttons.Count

      For i As Integer = 0 To Me._buttons.Count - 1
        Dim bRect As New Rectangle(butWidth * i, rect.Y, butWidth, rect.Height)
        Me._buttons(i).DrawButton(g, bRect, dpiFactor, drawButtonOutline)
      Next

      If drawRowOutline Then
        g.DrawRectangle(ControlButton.OutlinePen, rect)
      End If

      Me._lastRectangle = rect
    End If
  End Sub

  Public Sub Clear()
    For Each b As ControlButton In Me._buttons
      b.Clear()
    Next
    Me._buttons.Clear()
  End Sub

  ''' <summary>
  ''' Returns a deep copy of this object.  The returned object will be logically identical to the source object, but will share no references.
  ''' </summary>
  Public Function Copy() As ControlRow
    Dim cs As New ControlRow
    For Each b As ControlButton In Me._buttons
      cs.Buttons.Add(b.Copy)
    Next
    Return cs
  End Function
End Class
